﻿@model IEnumerable<QizSubject>
@{
    ViewBag.Title = "随访和检查单";
    ViewBag.Back = "/";

    bool userCanSubmit = SiteUser.AccountStatus != "102";
    var hosps = SiteUser.UserAllRecupers.Select(v => v.Hospital).Distinct();
    
}



@if (Model == null || Model.Count() == 0)
{
    <p class="data-empty">暂时还没有记录！</p>
}
else
{
    <div data-role="collapsible-set" data-inset="false" data-corners="false">
        @foreach (var h in hosps)
        {            
            string hospId = !String.IsNullOrEmpty(Request["HospitalID"]) ? Request["HospitalID"] 
                : (Session["MySF_HospitalID"] != null ? Session["MySF_HospitalID"].ToString() : "");
            <div data-role="collapsible" data-inset="false" data-corners="false" @(!String.IsNullOrEmpty(hospId) && h.HospitalID == hospId ? "data-collapsed=false" : "")>
                <h2>@h.HospName</h2>                
                <ul data-role="listview" data-inset="false" data-corners="false">
                    @foreach (var si in Model.Where(v => v.HospID == h.HospitalID && v.IsAllowInMobile).OrderByDescending(v => v.SortIdx))
                    {
                        string currentUrl = Request.Path + "?";
                        if (String.IsNullOrEmpty(Request["HospitalID"]))
                        {
                            if (Request.QueryString != null && Request.QueryString.Count > 0)
                            {
                                currentUrl += String.Format("{0}&HospitalID={1}#{2}", Request.QueryString.ToString(), h.HospitalID, si.ID);
                            }
                            else
                            {
                                currentUrl += String.Format("HospitalID={0}#{1}", h.HospitalID, si.ID);
                            }
                        }
                        else
                        {
                            var queryString = Request.QueryString != null && Request.QueryString.Count > 0
                                ? Request.QueryString.ToString() : "";
                            if (queryString != "")
                            {
                                queryString = queryString.Substring(0, queryString.IndexOf("HospitalID="));
                                currentUrl += String.Format("{0}&HospitalID={1}#{2}", queryString, h.HospitalID, si.ID);
                            }
                            else
                            {
                                currentUrl += String.Format("HospitalID={0}#{1}", h.HospitalID, si.ID);
                            }
                        }           
                        <li>
                            <h3>@Html.DisplayFor(modelItem => si.Department.BingQu.Title)&nbsp;&nbsp;@Html.DisplayFor(modelItem => si.Department.DepName)</h3>
                            <p>
                                @Html.ActionLink(si.Title, "QizSessionEdit", new { HospitalID = h.HospitalID, SubjectID = si.ID, Back = currentUrl }, new { name = si.ID })
                            </p>
                        </li>
                    }
                </ul>
            </div>
        }
    </div>
}
@section Scripts{
    @if (!String.IsNullOrEmpty(Request["HospitalID"]))
    {
        <script type="text/javascript">
            $(document).ready(function () {
                var anchorPos = window.location.href.indexOf('#');
                if (anchorPos != -1) {
                    var anchor = window.location.href.substring(anchorPos);
                    window.location.hash = anchor;
                }
            });
        </script>
    }
    else if (Session["MySF_SubjectID"] != null)
    {
        <script type="text/javascript">
            $(document).ready(function () {
                window.location.hash = '#@(Session["MySF_SubjectID"].ToString())';
            });
        </script>
    } 
}